package cms.manage.template.impl;

import cms.bean.user.AccessUser;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.ObjectUtils;

import java.util.Map;

/**
 * 抽象类
 */
public abstract class BaseTemplateManage {
    /**
     * 获取登录用户
     * @param runtimeParameter
     * @return
     */
    protected AccessUser getAccessUser(Map<String, Object> runtimeParameter) {
        //获取运行时参数
        if(MapUtils.isNotEmpty(runtimeParameter)){
            return (AccessUser)MapUtils.getObject(runtimeParameter,"accessUser");
        }
        return  null;
    }

    /**
     * 访问IP
     * @param runtimeParameter
     * @return
     */
    protected String getAccessIp(Map<String, Object> runtimeParameter) {
        //获取运行时参数
        if(MapUtils.isNotEmpty(runtimeParameter)){
            return MapUtils.getString(runtimeParameter,"ip");
        }
        return  null;
    }

    protected String getRequestURI(Map<String, Object> runtimeParameter) {
        //获取运行时参数
        if(MapUtils.isNotEmpty(runtimeParameter)){
            return MapUtils.getString(runtimeParameter,"requestURI");
        }
        return  null;
    }
    protected String getQueryString(Map<String, Object> runtimeParameter) {
        //获取运行时参数
        if(MapUtils.isNotEmpty(runtimeParameter)){
            return MapUtils.getString(runtimeParameter,"queryString");
        }
        return  null;
    }

    /**
     * 当前页
     * @param parameter
     * @return
     */
    protected Integer getParamPage(Map<String,Object> parameter){
        return ObjectUtils.defaultIfNull(MapUtils.getInteger(parameter,"page"),1);
    }
    /**
     * 页码显示总数
     * @param parameter
     * @return
     */
    protected Integer getParamPageCount(Map<String,Object> parameter){
        return ObjectUtils.defaultIfNull(MapUtils.getInteger(parameter,"pageSize"),10);
    }

}
